﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FogAI : Enemy {

    public float jumpForce;
    public Transform[] movePoints;
    private int index = 0;

    private Rigidbody2D rb;
    private bool isGround;
    private float dir = -1;
	// Use this for initialization
	protected override void Start () {
        base.Start();
        rb = GetComponent<Rigidbody2D>();

    }
	
	// Update is called once per frame
	void Update () {
        anim.SetBool("isGround", isGround);
        anim.SetFloat("Vertical", rb.velocity.y);
    }

    public void Jump()
    {

        float dis = Vector2.Distance(transform.position, movePoints[index].position);
        if (dis < 1f)
        {
            dir *= -1;
            GetComponent<SpriteRenderer>().flipX = dir > 0 ? true : false;
            index++;
            if (index >= movePoints.Length)
                index = 0;
        }
        rb.velocity = new Vector2(dir * 1.4f, 1.4f) * jumpForce;
    }

    private void OnCollisionEnter2D(Collision2D other)
    {

        if (other.gameObject.tag == "Ground")
            isGround = true;
    }

    private void OnCollisionExit2D(Collision2D other)
    {
        if (other.gameObject.tag == "Ground")
            isGround = false;
    }
}
